from sqlalchemy import String, Text, DateTime, ForeignKey, Integer
from sqlalchemy.orm import Mapped, mapped_column
from server.db.base import BaseModel


class Log(BaseModel):
    """
    日志模块： 日志表
    """
    __tablename__ = 'system_logs'

    user_id: Mapped[str] = mapped_column(String(20), nullable=True)
    method: Mapped[str] = mapped_column(String(10), nullable=False)
    path: Mapped[str] = mapped_column(String(255), nullable=False)
    params: Mapped[str] = mapped_column(Text, nullable=True)
    ip_address: Mapped[str] = mapped_column(String(50), nullable=True)
    user_agent: Mapped[str] = mapped_column(String(255), nullable=True)
    status_code: Mapped[int] = mapped_column(Integer, nullable=False)
    response: Mapped[str] = mapped_column(Text, nullable=True)


    def __repr__(self):
        return f"<SystemLog {self.action}>"